var names = ["abc","cba","sss"]


class Person{
    constructor(name,age){
        this.name = name
        this.age = age
        this._address = "广州市"
    }


    //普通实例方法
    //创建出来的对象进行访问
    eating(){
        console.log(this.name +"eating")
    }

    running(){
        console.log(this.age +"running")
    }
    //类的访问器方法
    get address(){
        console.log("拦截访问操作")
        return this._address
    }
    set address(newAddress){
        console.log("拦截设置操作")
        this._address = newAddress
    }
    //类的静态方法
    //  通过类名直接调用
    static randomPerson(){
        var nameIndex = Math.floor(Math.random() * names.length)
        var name = names[nameIndex]
        var age = Math.floor(Math.random()*100)
        return new Person(name,age)
    }
}
const p1 = new Person("scott",12)

// p1.eating()
// p1.running()

// console.log(p1.address)
// p1.address = "深圳市"
// console.log(p1.address)

for(var i = 0;i<50;i++){
    console.log(Person.randomPerson())
}